package inteface.utils;

import java.awt.Image;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class TransferableImage implements Transferable, ClipboardOwner {
	private Image image;
	
	public TransferableImage(Image uneImage) { 
		image = uneImage;
	}
	
	public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { 
		if (!isDataFlavorSupported(flavor))
			throw new UnsupportedFlavorException(flavor);
		return image;
	}
	
	public DataFlavor[] getTransferDataFlavors() {
		return new DataFlavor[]{DataFlavor.imageFlavor}; 
	}
	
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return DataFlavor.imageFlavor.equals(flavor);
	}
	
	public void finalize() {
		image = null;
	}

	public void lostOwnership(Clipboard clipboard, Transferable contents) {
		//System.out.println("lost");
		//finalize();
	}
}